<?php include('../../job/common/pdata_mysql.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>更新项目</title>
<style type="text/css">
.modi input {
	width: 350px;
	height: 30px;
}
.modi textarea {
	width: 350px;
	height: 50px;
}
.modi {
	font-size: 10px;
	width: 960px;
}
#stEdit {
	float: left;
	width: 960px;
}
</style>
<link href="/css/allstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header">
  <?php include("../../job/common/header.php") ?>
</div>
<?php
  	if(isset($_REQUEST['update']) )
	{//当传递过来的是stid的时候，判断为读取数据库，查看需要更新的情况。
	//此时可以修改数据，并且将对数据库进行更新。
		$pid = $_REQUEST['pid'];
		$projectname = $_REQUEST['projectname'];
		$oldname = $_REQUEST['oldname'];
		$donedraft = $_REQUEST['donedraft'];
		$startdate = $_REQUEST['startdate'];
		$enddate = $_REQUEST['enddate'];

		$sql = "UPDATE project SET ".
		"projectname = '".$projectname."',".
		"oldname = '".$oldname."',".
		"startdate = '".$startdate."',".
		"enddate = '".$enddate."',".
		"donedraft = '".$donedraft."' ".
		"WHERE pid = ".$pid;
		
		//echo "<p>".$sql."</p>";
		//update数据
		$conn = mysql_pconnect($hostname_pdata, $username_pdata, $password_pdata);
		mysql_select_db("pdata"); 
		if(mysql_query($sql,$conn) or die(mysql_error()))
		{		
		//重新读取，查询更新后的数据
		$sql = "select * from project where pid = ". $pid;
		$rs = mysql_query($sql,$conn);
		$row = mysql_fetch_array($rs) or die(mysql_error()); 
		//$stid = $row['stid'];
		$pid = $row['pid'];
		$projectname = $row['projectname'];
		$oldname = $row['oldname'];
		$donedraft = $row['donedraft'];
		$startdate = $row['startdate'];
		$enddate = $row['enddate'];
		}
		else
		{
			echo "UPDATE missed!Check the data and update again!";
		}
		
		mysql_close($conn);
	}
	
	else
	{//当传递过来的是stcode的时候，判断为更新查看及可以进行添加操作
		$pid = $_GET['pid'];
		  	
		$conn = mysql_pconnect($hostname_pdata, $username_pdata, $password_pdata);
		mysql_select_db("pdata"); 
		$sql = "select * from project where pid = ". $pid;
		$rs = mysql_query($sql,$conn);
		
		$row = mysql_fetch_array($rs) or die(mysql_error()); 
		//$stid = $row['stid'];
		$pid = $row['pid'];
		$projectname = $row['projectname'];
		$oldname = $row['oldname'];
		$donedraft = $row['donedraft'];
		$startdate = $row['startdate'];
		$enddate = $row['enddate'];
		mysql_close($conn);

	
	}
?>
<div id="wrap">
    <h1>正在修改：<?php echo $projectname;?></h1>
    <form id="station" name="station" method="get" action="">
      <input name="update" type="submit" id="update" value="更新" />
      <table class="modi">
        <tr>
          <th width="120">项目</th>
          <th width="360">内容</th>
          <th width="120">项目</th>
          <th width="360">内容</th>
        </tr>
        <tr>
          <td>编号</td>
          <td><input name="pid" type="text" id="pid" value="<?php echo $pid; ?>" readonly="readonly"  /></td>
          <td>输变电工程名称</td>
          <td><input name="projectname" type="text" id="projectname" value="<?php echo $projectname; ?>" /></td>
        </tr>
        <tr>
          <td>曾用名</td>
          <td><input name="oldname" type="text" id="oldname" value="<?php echo $oldname; ?>" /></td>
          <td>完成与否</td>
          <td><input name="donedraft" type="text" id="donedraft" value="<?php echo $donedraft; ?>" /></td>
        </tr>
        <tr>
          <td>首次开始日期</td>
          <td><input name="startdate" type="text" id="startdate" value="<?php echo $startdate; ?>" /></td>
          <td>送电或结束日期</td>
          <td><input name="enddate" type="text" id="enddate" value="<?php echo $enddate; ?>" /></td>
        </tr>
      </table>
    </form>
</div>
<div id="footer">
  <?php include("../../job/common/footer.php") ?>
</div>
</body>
</html>